package com.jpemartin.jgt;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * Maintains a boolean array: for each key, true if the key is pressed.
 * The idea is that you register a KeyboardStatus as KeyListener in your application
 * and then you can look up the array to see which keys are down.
 * 
 * @author jpmartin
 */
public class KeyboardStatus implements KeyListener {

  // keys: true if that key is down, false if it's up
  public boolean key[] = new boolean[255];

  public KeyboardStatus() {
    reset();
  }
  
  /** consider all keys "up" regardless of their actual state */
  public void reset() {
    java.util.Arrays.fill(key,false);
  }

  public void keyTyped(KeyEvent arg0) {
    key[arg0.getKeyCode() & 0xff] = true;
  }

  public void keyPressed(KeyEvent arg0) {
      key[arg0.getKeyCode() & 0xff] = true;

  }

  public void keyReleased(KeyEvent arg0) {
      key[arg0.getKeyCode() & 0xff] = false;
  }

}
